package com.sxz.sbs.module.client.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.client.bean.RealNameBean;
import com.sxz.sbs.module.client.bean.UploadFileBean;
import com.sxz.sbs.module.client.view.RealNameView;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;

import okhttp3.MultipartBody;

/**
 * Created by tian on 2018/1/26 0026.
 */

public class RealNamePresenter extends RxPresenter<RealNameView>{
    /**
     * 提交使命
     * @param map
     */
    public void submitRealName (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().submitRealName(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String data) {
                        mView.onSubmitAuthSuccess();
                    }
                })
        );
    }
    /**
     * 获取实名
     * @param map
     */
    public void getRealName (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getRealName(map)
                .compose(RxUtil.<RealNameBean>handleResult())
                .subscribeWith(new RxSubscriber<RealNameBean>(mView,true){
                    @Override
                    public void onNext(RealNameBean data) {
                        mView.onGetAuthSuccess(data);
                    }
                })
        );
    }
    /**
     * 上传文件
     */
    public void uploadAuth (int fileType,MultipartBody.Part file) {
        addSubscribe(App.getInstance().getApi().uploadFile(fileType,file)
                .compose(RxUtil.<UploadFileBean>handleResult())
                .subscribeWith(new RxSubscriber<UploadFileBean>(mView,true){
                    @Override
                    public void onNext(UploadFileBean info) {
                        mView.onUploadAuthSuccess(info);
                    }
                })
        );
    }
}
